// 导入创建路由的函数
import { createHashRouter, redirect } from 'react-router-dom';
import Home from '@/pages/home/index';
import Login from '@/pages/login/index';
import NotFound from '@/pages/notFound/404';
import { PAGE_TITLE } from '@/utils/constants';
import ResetPassword from '@/pages/login/resetPassword';

// 创建router路由实例对象，并配置路由对应关系（路由数组）
const router = createHashRouter([
  {
    path: '/',
    loader: () => {
      throw redirect('/home');
    },
  },
  {
    path: '/home',
    loader: () => (document.title = PAGE_TITLE),
    Component: Home,
  },
  {
    path: '/test/:id',
    Component: Home,
  },
  {
    path: '/login',
    children: [
      {
        path: '',
        loader: () => (document.title = `登录 - ${PAGE_TITLE}`),
        Component: Login,
      },
      {
        path: 'reset-password',
        loader: () => (document.title = `重置密码 - ${PAGE_TITLE}`),
        Component: ResetPassword,
      },
    ],
  },
  {
    path: '*',
    Component: NotFound,
  },
]);

export default router;
